package my.jwds.p203;

import my.jwds.p21.ListNode;

public class RemoveElements {
    public ListNode removeElements(ListNode head, int val) {
        ListNode temp = new ListNode();
        ListNode result = temp;
        while(head != null){
            if (head.val != val){
                temp.next = head;
                temp = temp.next;
                head = head.next;
                temp.next = null;
            }else{
                head = head.next;
            }
        }
        return result.next;
    }
}
